package com.xyc.servlet.main;

import com.xyc.mapper.UserMapper;
import com.xyc.pojo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/search")
public class SearchServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String info = req.getParameter("searchInfo"); // 小
        System.out.println("查找信息" + info);
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        UserMapper mapper = ctx.getBean("userMapper", UserMapper.class);
        List<User> likeList = mapper.userLike(info);
        HttpSession session = req.getSession();
        session.setAttribute("likeList", likeList);
        req.getRequestDispatcher("user/search.jsp").forward(req, resp);
    }
}
